import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:word_app/app/modules/model/app_https_client.dart';
import 'package:word_app/app/modules/model/toast_model.dart';
import 'package:word_app/app/modules/myWeb/views/my_web_view.dart';

class ChangePasswordController extends GetxController {
  RxString numberStr = ''.obs;
  TextEditingController vc = TextEditingController();
  TextEditingController vc1 = TextEditingController();
  AppHttpsClient httpsclien = AppHttpsClient();
  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {
    super.onReady();
  }

  @override
  void onClose() {
    super.onClose();
  }

  editPassworld(BuildContext context) async {
    if (vc.text.isEmpty) {
      ToastModel.showToast("密码不能为空");
      return;
    }
    if (vc.text != vc1.text) {
      ToastModel.showToast("两次密码不一致");
      return;
    }
    var response = await httpsclien
        .post("user/changePassword", {"password": "", "newPassword": ""});
    if (response == null) {
      ToastModel.showToast("修改失败");
    } else {
      if (response.statusCode == 200) {
        if (response.data["code"] == 200) {
          ToastModel.showToast("修改成功");
          Navigator.pushReplacement(
            context,
            MaterialPageRoute(builder: (context) => const MyWebView()),
          );
        } else {
          ToastModel.showToast("修改失败");
        }
      } else {
        ToastModel.showToast("修改失败");
      }
    }
  }
}
